import * as Request from '../request';
import { SuzhouDistrictMap } from '@config/map';
import { RankTOOL } from '@utils/index';

// 科创概览-产学研载体 地图柱状图、区域分布数据
export const GetAnalysisAPI = async (params) => {
  const url = '/api/iur/analysis';
  let res: any = [];
  try {
    res = await Request.post(url, params);
  } catch (error) {
    console.log('request error:', url, error);
  }

  const rankedRes = RankTOOL(res, 'value');

  return SuzhouDistrictMap.map((d) => {
    const item = rankedRes.find((r: any) => r.name === d.name);
    d.value = item?.value ?? -1;
    d.rank = item?.rank;

    return d;
  });
};

// 在苏部署、省属科研院所
export const IurRankAPI = async (params) => {
  const url = '/api/iur/institute';
  let res: any[] = [];
  try {
    res = await Request.post(url, params);
  } catch (error) {
    console.log('request error:', url, error);
  }

  return res;
};
